<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.jm.utils.StringHelper" %>
<%@include file="/include/common/printbackhead.jsp"%>
<%!private class PageAction extends BaseAction {
	StringBuilderEx sql = null;
	ResultSet rs = null;
	
	String wf001srn = "";//合同srn
	String ci = "";//批次
	
	protected void prepareActionEnv() throws Exception {
		sql = new StringBuilderEx();
		//範例
		wf001srn = "3946";
		ci = "1";
		
		form.spsv("wf001srn", wf001srn);
		form.spsv("ci", ci);
	}

	//請求處理結束
	protected void EndProcess() throws Exception {
		
	}

	//加載頁面默認數據
	protected boolean onLoadDefault() throws Exception {
		form.spov("printdate",new Date());
		onSearchRetrieveResult();
		return true;
	}	
	
	protected void onSearchRetrieveResult() throws Exception{
		if(form.isNullOrEmpty("wf001srn")) return ;
		 //1.取合同主档信息
		 rs = utils.executeQuery("info5","select  a.ht_no,a.factory,a.dept_no,a.qty,b.chfullname,style_cus from mf..wf001 a "
		 +"left join info.sys.dbo.sys004a b on a.sys004asn=b.sn  where a.srn='"+wf001srn+"' ");
		 if(rs.next())
		 	form.FromResultSet(rs,false);
		 
		 //2.取出發件批次信息
		 rs = utils.executeQuery("info5","select sum(qty) as qty,wt,dh,back_date from mf..wf003 "
		 +" where wf001srn = '"+wf001srn+"' and ci = '"+ci+"' "
		 +" group by dh,back_date,wt ");
		 if(rs.next())
		 	form.FromResultSet(rs,false);
		 
		 //3.取出發件批次的明細信息
		 if(!form.isNullOrEmpty("dh")){
		 	StringBuffer strDh = new StringBuffer();
		 	for(int i=0;i<form.gpsv("dh").split(",").length;i++){
		 		if(!StringHelper.IsNullOrEmpty(form.gpsv("dh").split(",")[i])){
			 		if(strDh.toString().length() > 0)
			 			strDh.append(",");
			 		strDh.append("'").append(form.gpsv("dh").split(",")[i]).append("'");
		 		}
		 	}
		 	
		 	if(strDh.length() >0){
		 		 rs = utils.executeQuery("info5",
		 		 	"select dh_no,gx_no,gx_name from mf..wf002b where  wf001srn = '"+wf001srn+"' and dh_no in("+strDh.toString()+") order by dh_no");
		 		 ret.SetSearchResult(rs);
		 	}
		 }
	}
}
%>
<%@include file="/include/common/printbackend.jsp"%>